load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "execinfrapb",
    srcs = [
        "aggregate_funcs.go",
        "api.go",
        "component_stats.go",
        "data.go",
        "expr.go",
        "flow_diagram.go",
        "processors.go",
        "testutils.go",
    ],
    embed = [":execinfrapb_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/roachpb",
        "//pkg/rpc",
        "//pkg/security/username",
        "//pkg/settings/cluster",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/catalogkeys",
        "//pkg/sql/catalog/catenumpb",
        "//pkg/sql/catalog/colinfo",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/fetchpb",
        "//pkg/sql/catalog/typedesc",
        "//pkg/sql/parser",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/rowenc",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/normalize",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sem/tree/treewindow",
        "//pkg/sql/sessiondata",
        "//pkg/sql/types",
        "//pkg/util",
        "//pkg/util/buildutil",
        "//pkg/util/duration",
        "//pkg/util/encoding",
        "//pkg/util/hlc",
        "//pkg/util/humanizeutil",
        "//pkg/util/netutil",
        "//pkg/util/optional",
        "//pkg/util/protoutil",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/tracing/tracingpb",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_dustin_go_humanize//:go-humanize",
        "@com_github_gogo_protobuf//types",
        "@org_golang_google_grpc//:go_default_library",
    ],
)

go_test(
    name = "execinfrapb_test",
    size = "small",
    srcs = [
        "component_stats_test.go",
        "expr_test.go",
        "flow_diagram_external_test.go",
        "flow_diagram_test.go",
    ],
    embed = [":execinfrapb"],
    deps = [
        "//pkg/base",
        "//pkg/keys",
        "//pkg/roachpb",
        "//pkg/security/username",
        "//pkg/settings/cluster",
        "//pkg/sql",
        "//pkg/sql/catalog/catpb",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/fetchpb",
        "//pkg/sql/rowenc",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/types",
        "//pkg/util/leaktest",
        "//pkg/util/optional",
        "@com_github_stretchr_testify//require",
    ],
)

proto_library(
    name = "execinfrapb_proto",
    srcs = [
        "api.proto",
        "component_stats.proto",
        "data.proto",
        "processors.proto",
        "processors_base.proto",
        "processors_bulk_io.proto",
        "processors_changefeeds.proto",
        "processors_sql.proto",
        "processors_table_stats.proto",
        "processors_ttl.proto",
    ],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/cloud/cloudpb:cloudpb_proto",
        "//pkg/jobs/jobspb:jobspb_proto",
        "//pkg/kv/kvpb:kvpb_proto",
        "//pkg/roachpb:roachpb_proto",
        "//pkg/sql/catalog/catenumpb:catenumpb_proto",
        "//pkg/sql/catalog/descpb:descpb_proto",
        "//pkg/sql/catalog/fetchpb:fetchpb_proto",
        "//pkg/sql/inverted:inverted_proto",
        "//pkg/sql/sessiondatapb:sessiondatapb_proto",
        "//pkg/sql/types:types_proto",
        "//pkg/util/hlc:hlc_proto",
        "//pkg/util/optional:optional_proto",
        "//pkg/util/tracing/tracingpb:tracingpb_proto",
        "@com_github_cockroachdb_errors//errorspb:errorspb_proto",
        "@com_github_gogo_protobuf//gogoproto:gogo_proto",
        "@com_google_protobuf//:any_proto",
        "@com_google_protobuf//:duration_proto",
        "@com_google_protobuf//:timestamp_proto",
    ],
)

go_proto_library(
    name = "execinfrapb_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_grpc_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb",
    proto = ":execinfrapb_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/cloud/cloudpb",
        "//pkg/jobs/jobspb",
        "//pkg/kv/kvpb",
        "//pkg/roachpb",
        "//pkg/sql/catalog/catenumpb",
        "//pkg/sql/catalog/catpb",  # keep
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/fetchpb",
        "//pkg/sql/inverted",
        "//pkg/sql/sessiondatapb",
        "//pkg/sql/types",
        "//pkg/util/hlc",
        "//pkg/util/optional",
        "//pkg/util/tracing/tracingpb",
        "@com_github_cockroachdb_errors//errorspb",
        "@com_github_gogo_protobuf//gogoproto",
    ],
)

disallowed_imports_test(
    "execinfrapb",
    ["//pkg/sql/sem/builtins"],
)
